package ldh.im.fxgui;

import io.netty.channel.DefaultFileRegion;
import ldh.im.fxbase.richtext.TextItem;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class SplitDemo {

    @Test
    public void split() {
        String str = "34343|~|emoji:asdfasfsadfasfa|~|";
        String[] ss = str.split("\\|~\\|");
        for(String s : ss) {
            if (!s.equals("")) {
                TextItem textItem = TextItem.parse(s);
                if (textItem != null) {
                    System.out.println("textItem:" + textItem.getData());
                } else {
                    System.out.println("s:" + s);
                }

            }
        }
    }

    @Test
    public void checkFile() {
        String fileName = "E:\\git\\im\\data\\im\\capture\\刘备\\20241011\\1728649736002unicy.png";
        String fileName2 = "E:\\git\\im\\data\\im\\capture\\刘备\\20241011\\1728649736002unicy_2.png";
        File file = new File(fileName);
        File file2 = new File(fileName2);
        long fileSize = file.length();

        try(FileInputStream fileInputStream = new FileInputStream(file);
            FileOutputStream fileOutputStream = new FileOutputStream(file2)
        ) {
            // 尝试创建FileRegion
            fileSize = fileInputStream.available();
            DefaultFileRegion region = new DefaultFileRegion(fileInputStream.getChannel(), 0, fileSize);
            region.transferTo(fileOutputStream.getChannel(), 0);
            System.out.println("FileRegion is supported.");
        } catch (Throwable e) {
            System.out.println("FileRegion is not supported: " + e.getMessage());
        }
    }
}
